package com.gw.vip.center.controller;

import com.gw.vip.center.dto.MailPassWordLoginDto;
import com.gw.vip.center.dto.MiniProgramLoginDto;
import com.gw.vip.center.dto.SessionKeyDto;
import com.gw.vip.center.dto.UnionInfoDto;
import com.gw.vip.center.vo.MailPassWordLoginVo;
import com.gw.vip.center.vo.MiniProgramLoginVo;
import com.gw.vip.center.vo.SessionKeyVo;
import com.gw.vip.center.vo.UnionLoginVo;
import com.gw.vip.center.zib.LoginBiz;
import com.gw.vip.common.log.PrintlnLog;
import com.gw.vip.common.vo.Result;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author GW
 * @description
 * @since 2022-03-29
 */
@RestController
@RequestMapping("login")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Slf4j
public class LoginController {

    private final LoginBiz loginBiz;

    /**
     * 联合登陆
     * @param unionInfoDto 入参
     * @return 统一返回体
     */
    @PostMapping("unionLogin")
    public Result unionLogin(@RequestBody UnionInfoDto unionInfoDto){
        UnionLoginVo vo = loginBiz.unionLogin(unionInfoDto);
        return Result.success(vo);
    }

    /**
     * 小程序登录。使用code登录。
     * @param miniProgramLoginDto
     * @return
     */
    @PrintlnLog(description = "小程序登录")
    @PostMapping("miniProgramLogin")
    public Result miniProgramLogin(@RequestBody @Valid MiniProgramLoginDto miniProgramLoginDto){
        MiniProgramLoginVo vo = loginBiz.miniProgramLogin(miniProgramLoginDto);
        return Result.success(vo);
    }

    @PrintlnLog(description = "会话密钥")
    @PostMapping("sessionKey")
    public Result sessionKey(@RequestBody @Valid SessionKeyDto dto){
        SessionKeyVo vo = loginBiz.sessionKey(dto);
        return Result.success(vo);
    }

    @PrintlnLog(description = "邮箱密码登录")
    @PostMapping("mailPassWordLogin")
    public Result mailPassWordLogin(@RequestBody @Valid MailPassWordLoginDto dto){
        MailPassWordLoginVo vo = loginBiz.mailPassWordLogin(dto);
        return Result.success(vo);
    }
}
